<?php
/**
 * 数据库单件类
 */
class db{
	static private $Instance = null;
	static function  getInstance(){
		$db_type = get_config('DB_TYPE');
		if(self::$Instance == null){
			try{
				if($db_type == 'mysql'){
					self::$Instance = new PDO('mysql:host='.get_config('DB_HOST').';dbname='.get_config('DB_NAME'), get_config('DB_USER'), get_config('DB_PWD'));
				}else{
					self::$Instance = new PDO('sqlite:'.BASE_PATH.'db/photo.db');
				}
			}catch(Exception  $e){
				echo 'Caught exception: ',  $e->getMessage(), "\n";
			}
		}
		return self::$Instance;
	}
}
